package com.btcode.web.core.controller;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * 对应controller里面具体的action方法
 *
 * @author gislin
 */
public class Action {

    private String actionURL;

    private Method actionMethod;

    private Controller controller;

    public Action(String actionURL, Method actionMethod, Controller controller) {
        this.actionURL = actionURL;
        this.actionMethod = actionMethod;
        this.controller = controller;

    }

    public String getActionURL() {
        return actionURL;
    }

    public void setActionURL(String actionURL) {
        this.actionURL = actionURL;
    }

    public Method getActionMethod() {
        return actionMethod;
    }

    public void setActionMethod(Method actionMethod) {
        this.actionMethod = actionMethod;
    }

    public Controller getController() {
        return controller;
    }

    public void setController(Controller controller) {
        this.controller = controller;
    }

    public void invoke(ServletRequest arg0, ServletResponse arg1)
        throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
        System.out.println("执行：" + controller.getClass().getName() + "." + actionMethod.getName());
        actionMethod.invoke(controller, new Object[]{arg0, arg1});
    }
}
